extends Spatial


# Declare member variables here. Examples:
# var a = 2
# var b = "text"
var x_sensitivity = 0
var y_sensitivity = 0
var is_drag = false
var planet
var helper
var camera
var view
var target
var universe
var interp

func _input(event):
	if event is InputEventMouseButton:
		if event.button_index == BUTTON_RIGHT:
			is_drag = event.pressed
		if event.button_index == BUTTON_WHEEL_UP and Global.zoom > 0.1:
			Global.zoom -= .1
			camera.translation = Vector3(0,0,pow(Global.zoom,4)+1.1)
		if event.button_index == BUTTON_WHEEL_DOWN:
			Global.zoom += .1
			#print(zoom)
			camera.translation = Vector3(0,0,pow(Global.zoom,4)+1.1)

	if event is InputEventMouseMotion and is_drag:
		self.rotate_y(event.relative.x/x_sensitivity)
		helper.rotate_x(event.relative.y/y_sensitivity)

# Called when the node enters the scene tree for the first time.
func _ready():
	x_sensitivity = -200
	y_sensitivity = -200
	helper = get_node("helper")
	camera = get_node("helper/target")
	view = get_node("helper/real_camera")
	camera.translation = Vector3(0,0,pow(Global.zoom,4)+1.1)
	Global.camera = view
	universe = get_node("../Sun")
	target = self
	interp = 0
	pass # Replace with function body.

func _physics_process(delta):
	var xform  = target.get_global_transform().origin * Vector3(-1,-1,-1)
	universe.translate(xform)
	pass

func _on_Control_camera_change(node):
	target = node
	interp = 0
	pass # Replace with function body.
